﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Happy.Domain;

namespace Happy.Examples.ManufactureManagement.Domain.SmallCuts
{
    public sealed class SmallCut : AggregateRoot<Guid>
    {
        public LockInfo LockInfo { get; private set; }

        internal void AcquireLock(LockInfo lockInfo)
        {
            if (this.LockInfo != null)
            {
                throw new InvalidOperationException("小分切正在被其它单据使用中");
            }

            this.LockInfo = lockInfo;
        }

        internal void ReleaseLock(LockInfo lockInfo)
        {
            if (this.LockInfo != lockInfo)
            {
                throw new InvalidOperationException("不能释放该锁，您不是自愿拥有者");
            }

            this.LockInfo = null;
        }
    }
}
